package mess;

import java.sql.SQLOutput;
import java.util.Arrays;

public class LeeCode_915 {
    public static void main(String[] args) {
        int[] nums = {5,0,3,8,6};
        System.out.println(partitionDisjoint(nums));
    }

    private static int partitionDisjoint(int[] nums) {
        int len = nums.length;
        int[] maxs = new int[len];
        int[] mins = new int[len];
        int max = nums[0];
        maxs[0] = max;
        int min = nums[len - 1];
        mins[len - 1] = min;
        for (int i = 0; i < len - 1; i++) {
            max = Math.max(max, nums[i + 1]);
            maxs[i + 1] = max;
        }
        for (int i = len - 1; i > 0; i--) {
            min = Math.min(min, nums[i - 1]);
            mins[i - 1] = min;
        }
        int count = 1;
        for (int i = 0; i < len - 1; i++) {
            if (maxs[i] <= mins[i + 1])
                break;
            count++;

        }
        return count;
    }
}
